/**
 *  @FileName: InstanceCounter.java
 *  @Last Modified Date: CharlW 2016.3.13
 *  @Description: static修饰符用来创建类方法和类变量
 */

public class InstanceCounter {
	private static int numInstances = 0;
	protected static int getCount() {
		return numInstances;
	}
	
	private static void addInstance() {
		numInstances++;
	}
	
	InstanceCounter() {
		InstanceCounter.addInstance();
	}
	
	public static void main(String args[]) {
		System.out.println("Starting with " +
			InstanceCounter.getCount() + " instance");
		for(int i = 0; i < 500; ++i) {
			new InstanceCounter();
		}
		System.out.println("Created " + 
			InstanceCounter.getCount() + " instance");
	}
}